package com.sleep.satokendemo.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sleep.satokendemo.entry.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName ExceptionHandle
 * @Description TODO  全局统一异常处理类
 * @Author 郭敖
 * @Date 2024年03月31日 19:06
 * @Version 1.0
 */
@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(Exception.class)
    public R handleException(Exception e) {
        return R.error(e.getMessage());
    }

    @ExceptionHandler(JsonProcessingException.class)
    public R handleJsonProcessingException(JsonProcessingException e) {
        return R.error(String.format("报文转换异常:%s",e.getMessage()));
    }
}
